<?php
class C_menus extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_menus');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			default :
				$this->load->view('v_menus');
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['menus_label'] = nosql_post("menus_label");
		$data['menus_kode'] = nosql_post("menus_kode");
		$data['menus_double'] = nosql_post("menus_double");
		$data['menus_icon'] = nosql_post("menus_icon");
		$data['menus_color'] = nosql_post("menus_color");
		$data['menus_url'] = nosql_post("menus_url");
		echo $this->m_menus->_list($data);
	}
	
	function _insert(){
		$data = array(
			'menus_label' => $this->input->post('menus_label'), 
			'menus_kode' => $this->input->post('menus_kode'), 
			'menus_double' => $this->input->post('menus_double'), 
			'menus_icon' => $this->input->post('menus_icon'), 
			'menus_color' => $this->input->post('menus_color'), 
			'menus_url' => $this->input->post('menus_url'), 
			  
			'menus_sys_active'=> '1',
			'menus_sys_owner'	=>$_SESSION[SESSION_USERID]);
		$this->m_menus->_insert($data);
		echo 1;
	}
	
	function _update(){
		$menus_id = $this->input->post('menus_id');
		$data = array(
			'menus_label' => $this->input->post('menus_label'), 
			'menus_kode' => $this->input->post('menus_kode'), 
			'menus_double' => $this->input->post('menus_double'), 
			'menus_icon' => $this->input->post('menus_icon'), 
			'menus_color' => $this->input->post('menus_color'), 
			'menus_url' => $this->input->post('menus_url'), 
			
			'menus_sys_owner'	=> $_SESSION[SESSION_USERID],
			'menus_sys_update'=> date("Y-m-d h:i:s"));
		$this->m_menus->_update($data,$menus_id);
		echo 1;
 	}
	
	function _delete(){
		$menus_id= $this->input->post('menus_id');
		$data = array(
			'menus_sys_active' => '0',
			'menus_sys_owner'	=> $_SESSION[SESSION_USERID],
			'menus_sys_delete'=> date("Y-m-d h:i:s")
		);
		$this->m_menus->_delete($data,$menus_id);
		echo 1;
	}
}